#ifndef GENE_H
#define GENE_H

#include <QGraphicsWidget>
#include <QString>
#include <QRectF>
#include <QPainterPath>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <QGraphicsSceneHoverEvent>
#include <QGraphicsSceneMouseEvent>
#include <QDebug>
#include <QColorDialog>
#include <QGraphicsProxyWidget>
#include <QKeyEvent>

//class Contig;
class GenomeSegment;
class InfoBox;
class QualitativeAttribute;

class Gene : public QGraphicsWidget
{
    Q_OBJECT
public:
    explicit Gene(QString geneId, int start, int stop, bool isPos, GenomeSegment *parent = 0);//Contig *parent = 0);

    int getStart();
    int getStop();
    QString getGeneId();
    bool getIsPosStrand();

    void setWidth( float newHeight );
    void setHeight( float newWidth );

    void addAttribute( QString attribute, QString attributeName );
    void addAttribute( QString attribute, QString attributeName,  QList<float> confidenceMetric, QList<QString> confidenceMetricLabel );

    QRectF boundingRect() const;
    QPainterPath shape() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
               QWidget *widget);

    ~Gene();
signals:
    void hoverEnterOverGeneSignal( );
    void hoverLeaveOverGeneSignal( );//these signals are connected to genes of the same kind in other contigs

    void geneSelectedSignal();

    void alignWithThisGene( float locOfGeneX , bool posStrand );//this signal goes out to the genes as well- indicating that it is nec to calculat the dist
                                //the entire contig must move to line up with gene
                                //this is relative to the parent

    void alignmentEvent( QString geneToAlignAgainst, QPointF posInWidget, int direction );

    void changeGeneColorSignal( QColor c );

public slots:
    void hoverEnterOverGeneSlot();
    void hoverLeaveOverGeneSlot();

    void geneSelectedSlot();

    void calculateReAlignment(float, bool);

    void changeGeneColorSlot( QColor c );

    void keyPressEvent ( QKeyEvent * event );

protected:
    void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
    void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
    void changeAfterHoverEnter();
    void changeAfterHoverLeave();

    void mousePressEvent(QGraphicsSceneMouseEvent *event);

private:
    QString geneId;
    int start;
    int stop;
    bool isPosStrand;

    float width;
    float height;

    QList< QualitativeAttribute* > attributes;
    InfoBox* geneInfo;

    bool hovering;
    bool selected;

    QColor* unselectedColor;
    QColor* highlightedColor;
    QColor* userGivenColor;
    QColor* colorToDraw;
    QColor* backgroundColor;

    GenomeSegment* parent;

    bool alignKeyPressed;
    bool flipKeyPressed;
    bool colorKeyPressed;

//    void drawArrow( const QRectF& body, const QPointF& p1, const QPointF& p2, const QPointF& p3, const QColor& color );

};

#endif // GENE_H
